<?

session_start();

include_once("../classCol.php");

include_once("../helpers/CHtml.php");
include_once("../helpers/CJavascript.php");
include_once("../helpers/Composer.php");
include_once("../helpers/ComposerSourceDb.php");

include_once("models/fetchers.php");
include_once("models/handlers.php");
include_once("controllers/local.php");

include_once("../models/GHandlers.php");
include_once("../models/GFetchers.php");
include_once("../models/GlobalHandlers.php");
include_once("../models/GlobalFetchers.php");
include_once("../controllers/GlobalProcessors.php");

/**
* Optional defines
*
*/
define("_USER_ID"       , 0);
define("_USER_COMPANY"  , 1);

$stlButton = " ";

//check what authoration
$UID	=	unserialize($_SESSION["serUID"]);

$thisMdl	    = "Warehouse";
$modulNumber = "";

$srcDbHdr = "USERID_HDR";
$srcDbDtl = "USERID_DTL";

$CFetchers  = new CGFetchers;
$CHandlers  = new CGHandlers;

$CLHandlers = new CLHandlers;
$CLFetchers = new CLFetchers;
$CLocal     = new CLocal;

$Misc       = new Misc;
$GHtml      = new CGHtml;
$GJs        = new CGJavascript;
$GProcessors= new GlobalProcessors;

$SourceDb   = new Composer;
$SourceDb   = $SourceDb->init("db");

$SourceDb->add("srcDbHdr",      "MST_WAREHOUSE");
$SourceDb->add("srcDbDtl",      "MST_WAREHOUSE");

$check_me_authed          = "NO_OK";
$_SESSION["modify_mode"]  = "N";

$_SESSION["reauthed"] = ($_SESSION["reauthed"] != "")? $_SESSION["reauthed"] : "N";
$_SESSION["recheck"]  = ($_SESSION["recheck"]  != "")? $_SESSION["recheck"]  : "N";

echo  $GJs->includeThis(_TYPE_CSS,"/ecs/myMenu.css");

/**
* Only by pass entry mode and back
* else needs to relogin
*
*/
if($_POST["entry"] ||
   $_POST["back"]  ||
   $_POST["view"]){

  if($_POST["entry"]){

    jumpTo(0,"entry.php");
  }else
  if($_POST["back"]){

    jumpTo(0,"../".$_SESSION["source_caller"]);
  }else
  if($_POST["view"]){

    require("viewdboredit_view.php");
  }else{

    /* Do nothing */
  }
}else{

  if($_SESSION["reauthed"]  == "N" &&
     $_SESSION["recheck"]   == "N"){

    $_SESSION["temp_radioview"] = $_POST["radioview"];
    $_SESSION["temp_selbox"]    = $_POST["selbox"];

    $_SESSION["recheck"] = "Y";

		$flsMessage = "Validity Check";
		$tgtUrl     = "viewdboredit.php";
		$btnLabel   = "Submit";

		$Misc->thisButton($_POST,
		                  $btnName,
		                  $btnValue);

		$GProcessors->procChkValidation($flsMessage,
                                    $tgtUrl,
                                    $btnLabel,
                                    $btnName,
                                    $btnValue,
                                    $stlButton);
  }else
  if($_SESSION["reauthed"]  == "N" &&
     $_SESSION["recheck"]   == "Y"){

    $Db = new oracleDb;

  	$Db->init($_SESSION["ORCLU"],
              $_SESSION["OPASS"],
              $_SESSION["SID"],
              _NO_COMMENT);

    if($Db->connect()){

      $Misc->fetchRelogin($Db,
        			            $_POST["reauth_user"],
        			            $_POST["reauth_pass"],
        			            $_SESSION["company"],
        			            $srcDbHdr,
        			            $nrows,
        			            $_SESSION["user_id_reauth"]);

      if($nrows > 0 ){

  			$mode = $Misc->thisMode($_POST);

  			if($UID->getPrivsByNumber( $modulNumber, $mode) > 0){

  				$_SESSION["reauthed"] = "Y";

  				$flsMessage = "Login Ok";
      		$tgtUrl     = "viewdboredit.php";
      		$btnLabel   = "Continue";

      		$Misc->thisButton($_POST,
      		                  $btnName,
      		                  $btnValue);

  				$GProcessors->formOkValidated($flsMessage,
                				                $tgtUrl,
                				                $btnLabel,
               				                  $btnName,
               				                  $btnValue,
              				                  $stlButton);

  			}else{

  				unset($_SESSION["reauthed"]);
          unset($_SESSION["recheck"]);

  				$Misc->usrError("Authed Error reason : ".$chk_res." ");
  			}
  		}else{

  			$Db->dc();

  			$_SESSION["recheck"] = "Y";
  			$flsMessage = "Validity Check";
    		$tgtUrl     = "viewdboredit.php";
    		$btnLabel   = "Submit";

    		$Misc->thisButton($_POST,
    		                  $btnName,
    		                  $btnValue);

    		$GProcessors->procChkValidation($flsMessage,
                                        $tgtUrl,
                                        $btnLabel,
                                        $btnName,
                                        $btnValue,
                                        $stlButton);
  		}
    }else{

      $Misc->usrDieJs(_DB_CONN_ERROR);
    }
  }else
  if($_SESSION["reauthed"]  == "Y" &&
     $_SESSION["recheck"]   == "Y"){

    unset($_SESSION["reauthed"]);
    unset($_SESSION["recheck"]);

    $check_me_authed = "OK";

    if($_POST["modify"]){

      if($_POST["radioview"] == ''){

  			$_POST["radioview"] = $_SESSION["temp_radioview"] ;
  		}

		  require("viewdboredit_modify.php");
    }else
    if($_POST["delete"]){

      $_POST["selbox"] = $_SESSION["temp_selbox"] ;

      require("viewdboredit_delete.php");
    }else
    if($_POST["approve"]){

      $_POST["selbox"] = $_SESSION["temp_selbox"] ;

      require("viewdboredit_approve.php");
    }else
    if($_POST["cancel"]){

      $_POST["selbox"] = $_SESSION["temp_selbox"] ;

      require("viewdboredit_cancel.php");
    }else{

      /* DO nothing */
    }
  }else{

    $_SESSION["recheck"] = "Y";

		$flsMessage = "Validity Check";
		$tgtUrl     = "viewdboredit.php";
		$btnLabel   = "Submit";

		$Misc->thisButton($_POST,
		                  $btnName,
		                  $btnValue);

		$GProcessors->procChkValidation($flsMessage,
                                    $tgtUrl,
                                    $btnLabel,
                                    $btnName,
                                    $btnValue,
                                    $stlButton);
  }
}
?>  